package com.szit.test.servlet;

import com.szit.test.biz.SaleBiz;
import com.szit.test.biz.impl.SaleBizImpl;
import com.szit.test.entity.Sale;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name="isExistsServlet", urlPatterns = "/sys/isExistsId")
public class IsExistsSaleServlet extends HttpServlet {
    private static final long serialVersionUID = -5691917997491659197L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        int id = Integer.parseInt(request.getParameter("id").trim());
        SaleBiz teacherBiz = new SaleBizImpl();
        try {
            Sale t = teacherBiz.search(id);
            boolean flag = false;
            if (t != null) {
                flag = true;
            }
            PrintWriter out = response.getWriter();
            out.print(flag);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        doGet(request,response);
    }
}
